package com.example.controller;

import com.example.entity.TShopProduct;
import com.example.service.ITShopProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hc
 * @since 2025-09-08
 */
@Slf4j
@RestController
@RequestMapping("/product")
public class TShopProductController {

    @Autowired
    private ITShopProductService shopProductService;

    @Value("${server.port}")
    private String port; // 注入当前服务端口号

    @RequestMapping("/get/{pid}")
    public TShopProduct getById(@PathVariable("pid") Long pid) {

        log.info("调用product服务的getById方法");

        TShopProduct product = shopProductService.getById(pid);
        product.setPname(product.getPname() + ":" + port);
        return product;
    }
}
